<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;

Route::group('admin', function(){
    Route::redirect('/', HTTP_MANGE_URL . '/admin/login.html', 302);

    //不需要登录验证
    Route::group(function(){
        Route::get('captcha', 'admin.module.common.Index/verify');
        //登录
        Route::group('login', function (){
            Route::get('/', 'admin.module.login.Index/index');
            Route::post('/', 'admin.module.login.Index/login');
            Route::get('logout', 'admin.module.login.Index/logout');
        });
    });

    //需要登录后才能操作
    Route::group(function(){
        //主页
        Route::group('index', function (){
            Route::get('/', 'admin.module.index.Index/index');
        });

        //菜单
        Route::group('menu', function (){
            Route::post('reload', 'admin.module.menu.Index/reloadSecondaryMethod');
        });

        Route::group('common', function(){
            Route::group('upload', function (){
                Route::post('image', 'admin.module.common.Index/uploadImage')->name('uploadImage');
                Route::delete('image', 'admin.module.common.Index/delImage')->name('delImage');
            });
        });

        $requestMethod = [
            1 => 'get',
            2 => 'post',
            3 => 'put',
            4 => 'delete'
        ];
        $list = RouteMenuList();
        if(!empty($list)){
            foreach ($list as $v){
                if(($v['is_home_page'] != 1 and $v['level'] == 1) or empty($v['module'])){
                    continue;
                }
                $v['request_method'] = $requestMethod[$v['request_method']] ? : 'get';
                Route::group($v['module'], function () use ($v){
                    Route::{$v['request_method']}( (!empty($v['method']) ? ($v['method_alias'] ? : strtolower($v['method'])) : '/'),  'admin.module.' . ($v['module'] . '.Index/' . ($v['method'] ? : 'index')) );
                });
            }
        }
    })->middleware('AdminAuth');
})->domain(MANAGE_DOMAIN_NAME);